package com.diors.commons.network;

import org.jboss.netty.buffer.ChannelBuffer;

/**
 * 网络监听接口
 * @author	darren.ouyang <ouyang.darren@gmail.com>
 * @date	2013-10-21
 * @version 1.0
 * @copyright Copyright (c) 2013, darren.ouyang
 */
public abstract class NetworkListener <T extends AbstractConnection>
{
	
	/**
	 * 新连接接入监听
	 * @param conn	连接
	 * @create	2013-10-21	darren.ouyang
	 */
	protected abstract void connected (T conn);
	
	/**
	 * 连接关闭监听
	 * @param conn	连接
	 * @create	2013-10-21	darren.ouyang
	 */
	void close (T conn)
	{
		close(conn, "网络连接断开！！");
	}
	
	/**
	 * 连接关闭监听
	 * @param conn	连接
	 * @param info	关闭信息
	 * @create	2013-10-21	darren.ouyang
	 */
	protected abstract void close (T conn, String info);
	
	/**
	 * 接收到数据监听
	 * @param conn	连接
	 * @param rb	数据包
	 * @return
	 * @create	2013-10-21	darren.ouyang
	 */
	protected abstract boolean messageReceived (T conn, ChannelBuffer rb);
}
